package com.tang.framework.config.jackson;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author tang jun liang
 * @Date 2023/8/4 14:10
 */

@SpringBootConfiguration
public class JacksonConfig  {


    @Bean("jackson2ObjectMapperBuilderCustomizer")
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Map<Class<?>, JsonSerializer<?>> jsonSerializerMap = new HashMap<>(2);
        jsonSerializerMap.put(Long.class, LongSerializer.instance);
        jsonSerializerMap.put(Long.TYPE, LongSerializer.instance);
        Map<Class<?>, JsonDeserializer<?>> jsonDeserializerMap = new HashMap<>(2);
        jsonDeserializerMap.put(BigDecimal.class, CustomizeBigDecimalDeserializer.instance);
        return builder -> builder.serializersByType(jsonSerializerMap).deserializersByType(jsonDeserializerMap);
    }
}
